﻿//===============================================================================
// La Pomme d'Or Krystal Application
// Windows Presentation Foundation Composite Application 
//===============================================================================
// Copyright (c) Jérôme Piquot.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections;
using System.Collections.Generic;

namespace PJ.Data
{
    /// <summary>
    /// Get data modes
    /// </summary>
    public enum GetDataMode
    {
        /// <summary>
        /// Default, gets without using cache and throw error if object not found
        /// </summary>
        Default = 0x00,
        /// <summary>
        /// Use cache to get object. If not in cache gets it from the provider
        /// </summary>
        UseCache = 0x01,    
        /// <summary>
        /// Returns null if object not found instead of throwing an exception
        /// </summary>
        Find = 0x02,        
        /// <summary>
        /// Combines UseCache and Find 
        /// </summary>
        CachedFind = 0x03  
    };

    /// <summary>
    /// <see cref="IObjectData">Object data</see> persistence provider interface
    /// </summary>
    public interface IObjectProvider : IDisposable
    {
        /// <summary>
        /// Gets the data object from the data source
        /// </summary>
        /// <param name="globalId">Object global id</param>
        /// <param name="mode">Get mode. <see cref="GetDataMode"/> </param>
        /// <returns>The data object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="globalId"/> is <see langref="null"/> or empty</exception>
        /// <exception cref="DataNotFoundException">If the object with the specified GlobalId is not found and <paramref name="mode"/> is not Find</exception>
        IObjectData GetData(string globalId, GetDataMode mode);

        /// <summary>
        /// Gets a list of data objects from the data source
        /// </summary>
        /// <param name="globalIds">Object global id list</param>
        /// <param name="mode">Get mode. <see cref="GetDataMode"/> </param>
        /// <returns>The data object list</returns>
        /// <exception cref="ArgumentNullException"><paramref name="globalIds"/> is <see langref="null"/> or empty</exception>
        IEnumerable GetList(string[] globalIds, GetDataMode mode);

        /// <summary>
        /// Persists the data object and reloads it
        /// </summary>
        /// <param name="data">Object to persist</param>
        /// <returns>persisted data</returns>
        /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langref="null"/></exception>
        IObjectData PersistAndGet(IObjectData data);

        /// <summary>
        /// Persists the data object in the data source
        /// </summary>
        /// <param name="data">Object to persist</param>
        /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langref="null"/> </exception>
        void Persist(IObjectData data);

        /// <summary>
        /// Checks if the data object exists in the data source
        /// </summary>
        /// <param name="globalId">Object global id</param>
        /// <returns>true if found in data source else false</returns>
        /// <exception cref="ArgumentNullException"><paramref name="globalId"/> is <see langref="null"/> or empty</exception>
        bool Exist(string globalId);

        /// <summary>
        /// Removes the data object from the data source
        /// </summary>
        /// <param name="globalId">Object global id</param>
        /// <exception cref="ArgumentNullException"><paramref name="globalId"/> is <see langref="null"/> or empty</exception>
        /// <exception cref="DataNotFoundException">The object with the specified GlobalId is not found</exception>
        void Delete(string globalId);

        /// <summary>
        /// Creates a new instance of the concrete class
        /// </summary>
        /// <returns>The data object if found or throws an exception</returns>
        IObjectData CreateNewItem();

    }
    /// <summary>
    /// <see cref="IObjectData">Object data</see> persistence provider interface
    /// </summary>
    /// <typeparam name="TIObjectData"><see cref="IObjectData">Object data</see> type</typeparam>
    public interface IObjectProvider<TIObjectData> : IObjectProvider
        where TIObjectData : class, IObjectData
    {
        /// <summary>
        /// Gets the data object from the data source
        /// </summary>
        /// <param name="globalId">Object global id</param>
        /// <param name="mode">Get mode. <see cref="GetDataMode"/> </param>
        /// <returns>The data object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="globalId"/> is <see langref="null"/> or empty</exception>
        /// <exception cref="DataNotFoundException">If the object with the specified GlobalId is not found and <paramref name="returnNullIfNotFound"/> is false</exception>
        new TIObjectData GetData(string globalId, GetDataMode mode);

        /// <summary>
        /// Gets a list of data objects from the data source
        /// </summary>
        /// <param name="globalIds">Object global id list</param>
        /// <param name="mode">Get mode. <see cref="GetDataMode"/> </param>
        /// <returns>The data object list</returns>
        /// <exception cref="ArgumentNullException"><paramref name="globalIds"/> is <see langref="null"/> or empty</exception>
        /// <remarks>Using list instead of IEnumerable because the WCF needs concrete classes</remarks>
        new List<TIObjectData> GetList(string[] globalIds, GetDataMode mode);

        /// <summary>
        /// Persists the data object in the data source
        /// </summary>
        /// <param name="data">Object to persist</param>
        /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langref="null"/></exception>
        void Persist(TIObjectData data);

        /// <summary>
        /// Persists the data object in the data source and reloads it.
        /// </summary>
        /// <param name="data">Object to persist</param>
        /// <returns>persisted data</returns>
        /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langref="null"/></exception>
        TIObjectData PersistAndGet(TIObjectData data);

        /// <summary>
        /// Creates a new instance of the concrete class
        /// </summary>
        /// <returns>The data object if found or throws an exception</returns>
        new TIObjectData CreateNewItem();

    }
}
